package fr.unice.CD.calendar;

import java.util.GregorianCalendar;

public class Semaine {
	
	public static int day_of_first_day_of_week = -1;
	public static int month_of_first_day_of_week = -1;
	public static int year_of_first_day_of_week = -1;

	public static int day_of_second_day_of_week = -1;
	public static int month_of_second_day_of_week = -1;

	public static int day_of_third_day_of_week = -1;
	public static int month_of_third_day_of_week = -1;
	
	public static int day_of_fourth_day_of_week = -1;
	public static int month_of_fourth_day_of_week = -1;
	
	public static int day_of_fifth_day_of_week = -1;
	public static int month_of_fifth_day_of_week = -1;
	
	public static int day_of_sixth_day_of_week = -1;
	public static int month_of_sixth_day_of_week = -1;
	
	public static int day_of_seventh_day_of_week = -1;
	public static int month_of_seventh_day_of_week = -1;
	public static int year_of_seventh_day_of_week = -1;
	
	private static GregorianCalendar calendrierALaDateDuJour;
	//double de calendrierALaDateDuJour
	private static GregorianCalendar week;
		
	
	public static void initVarOfTheWeek(GregorianCalendar aujourdhui) {
		calendrierALaDateDuJour = aujourdhui;
		//creer un double du calendrierALaDateDuJour pour ne pas modifier ce dernier
		week = calendrierALaDateDuJour;
		
		switch(calendrierALaDateDuJour.get(GregorianCalendar.DAY_OF_WEEK)){
			case 1 :
				//si je suis dim (DAY_OF_WEEK 1 ) alors :
				//je trouve le premier jour de la semaine
				week.add(GregorianCalendar.DATE, -6);
				day_of_first_day_of_week = week.get(GregorianCalendar.DATE);
				month_of_first_day_of_week = week.get(GregorianCalendar.MONTH)+1;
				year_of_first_day_of_week = week.get(GregorianCalendar.YEAR);
				initOtherVar();
				break;
				
			case 2 :
				//si je suis lundi (DAY_OF_WEEK 2) alors je fais 
				day_of_first_day_of_week = week.get(GregorianCalendar.DATE);
				month_of_first_day_of_week = week.get(GregorianCalendar.MONTH)+1;
				year_of_first_day_of_week = week.get(GregorianCalendar.YEAR);
				initOtherVar();
				break;
				
			case 3 :
				//si je suis mar (DAY_OF_WEEK 3 ) alors je fais 
				week.add(GregorianCalendar.DATE, -1);
				day_of_first_day_of_week = week.get(GregorianCalendar.DATE);
				month_of_first_day_of_week = week.get(GregorianCalendar.MONTH)+1;
				year_of_first_day_of_week = week.get(GregorianCalendar.YEAR);
				initOtherVar();
				break;
				
			case 4 :
				//si je suis mer (DAY_OF_WEEK 4 ) alors je fais 
				week.add(GregorianCalendar.DATE, -2);
				day_of_first_day_of_week = week.get(GregorianCalendar.DATE);
				month_of_first_day_of_week = week.get(GregorianCalendar.MONTH)+1;
				year_of_first_day_of_week = week.get(GregorianCalendar.YEAR);
				initOtherVar();
				break;
				
			case 5 :
				//si je suis jeu (DAY_OF_WEEK 5 ) alors je fais 
				week.add(GregorianCalendar.DATE, -3);
				day_of_first_day_of_week = week.get(GregorianCalendar.DATE);
				month_of_first_day_of_week = week.get(GregorianCalendar.MONTH)+1;
				year_of_first_day_of_week = week.get(GregorianCalendar.YEAR);
				initOtherVar();
				break;
				
			case 6 :
				//si je suis ven (DAY_OF_WEEK 6 ) alors je fais 
				week.add(GregorianCalendar.DATE, -4);
				day_of_first_day_of_week = week.get(GregorianCalendar.DATE);
				month_of_first_day_of_week = week.get(GregorianCalendar.MONTH)+1;
				year_of_first_day_of_week = week.get(GregorianCalendar.YEAR);
				initOtherVar();
				break;
				
			case 7 :
				//si je suis sam (DAY_OF_WEEK 7 ) alors je fais 
				week.add(GregorianCalendar.DATE, -5);
				day_of_first_day_of_week = week.get(GregorianCalendar.DATE);
				month_of_first_day_of_week = week.get(GregorianCalendar.MONTH)+1;
				year_of_first_day_of_week = week.get(GregorianCalendar.YEAR);
				initOtherVar();
				break;
		}
	}
	
	private static void initOtherVar(){
		
		//j incremente le calendrier pour trouver les autres jours
		week.add(GregorianCalendar.DATE, +1);
		day_of_second_day_of_week = week.get(GregorianCalendar.DATE);
		month_of_second_day_of_week = week.get(GregorianCalendar.MONTH)+1;
		
		week.add(GregorianCalendar.DATE, +1);
		day_of_third_day_of_week = week.get(GregorianCalendar.DATE);
		month_of_third_day_of_week = week.get(GregorianCalendar.MONTH)+1;
		
		week.add(GregorianCalendar.DATE, +1);
		day_of_fourth_day_of_week = week.get(GregorianCalendar.DATE);
		month_of_fourth_day_of_week = week.get(GregorianCalendar.MONTH)+1;
		
		week.add(GregorianCalendar.DATE, +1);
		day_of_fifth_day_of_week = week.get(GregorianCalendar.DATE);
		month_of_fifth_day_of_week = week.get(GregorianCalendar.MONTH)+1;
		
		week.add(GregorianCalendar.DATE, +1);
		day_of_sixth_day_of_week = week.get(GregorianCalendar.DATE);
		month_of_sixth_day_of_week = week.get(GregorianCalendar.MONTH)+1;
		
		week.add(GregorianCalendar.DATE, +1);
		day_of_seventh_day_of_week = week.get(GregorianCalendar.DATE);
		month_of_seventh_day_of_week = week.get(GregorianCalendar.MONTH)+1;
		year_of_seventh_day_of_week = week.get(GregorianCalendar.YEAR);
	}
}
